use of mage.filter.FilterCard in project mage by magefree.
the class MasterOfPredicamentsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
if (!controller.getHand().isEmpty()) {
Card cardFromHand = null;
if (controller.getHand().size() > 1) {
TargetCard target = new TargetCardInHand(new FilterCard());
if (controller.choose(Outcome.PlayForFree, controller.getHand(), target, game)) {
cardFromHand = game.getCard(target.getFirstTarget());
}
} else {
cardFromHand = controller.getHand().getRandom(game);
}
if (cardFromHand == null) {
return false;
}
Player attackedPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
if (attackedPlayer == null) {
return false;
}
boolean guessWrong;
if (attackedPlayer.chooseUse(Outcome.Detriment, "Is the chosen card's " + "mana value greater than 4?", source, game)) {
game.informPlayers(attackedPlayer.getLogName() + " guessed that the chosen " + "card's mana value is greater than 4");
guessWrong = cardFromHand.getManaValue() <= 4;
} else {
game.informPlayers(attackedPlayer.getLogName() + " guessed that the chosen " + "card's mana value is not greater than 4");
guessWrong = cardFromHand.getManaValue() > 4;
}
game.informPlayers(attackedPlayer.getLogName() + " guessed " + (guessWrong ? "wrong" : "right"));
if (guessWrong) {
if (cardFromHand.isLand(game)) {
// If the revealed card is a land, you can't cast it. So nothing happens
} else {
if (controller.chooseUse(outcome, "Cast " + cardFromHand.getName() + " without paying its mana cost?", source, game)) {
game.getState().setValue("PlayFromNotOwnHandZone" + cardFromHand.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(cardFromHand, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + cardFromHand.getId(), null);
}
}
}
}
return true;
}
return false;
}
use of mage.filter.FilterCard in project mage by magefree.
the class NecromanticSelectionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject != null && controller != null) {
Cards cards = new CardsImpl();
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, controller.getId(), source.getSourceId(), game)) {
permanent.destroy(source, game, false);
// Meren of the Clan Nel Toth bug #8515
game.checkStateAndTriggered();
if (game.getState().getZone(permanent.getId()) == Zone.GRAVEYARD) {
cards.add(permanent);
}
}
FilterCard filter = new FilterCreatureCard("creature card put into a graveyard with " + sourceObject.getLogName());
List<Predicate<MageObject>> cardIdPredicates = new ArrayList<>();
for (UUID cardId : cards) {
cardIdPredicates.add(new CardIdPredicate(cardId));
}
filter.add(Predicates.or(cardIdPredicates));
Target target = new TargetCardInGraveyard(filter);
target.setNotTarget(true);
if (controller.chooseTarget(Outcome.Benefit, target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
ContinuousEffect effect = new BecomesBlackZombieAdditionEffect();
effect.setText("It's a black Zombie in addition to its other colors and types");
effect.setTargetPointer(new FixedTarget(card.getId(), game));
game.addEffect(effect, source);
}
}
return true;
}
return false;
}
use of mage.filter.FilterCard in project mage by magefree.
the class NecromentiaEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
Player controller = game.getPlayer(source.getControllerId());
if (cardName != null && controller != null) {
FilterCard filter = new FilterCard("card named " + cardName);
filter.add(new NamePredicate(cardName));
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
// cards in Graveyard
int cardsCount = (cardName.isEmpty() ? 0 : targetPlayer.getGraveyard().count(filter, game));
if (cardsCount > 0) {
filter.setMessage("card named " + cardName + " in the graveyard of " + targetPlayer.getName());
TargetCard target = new TargetCard(0, cardsCount, Zone.GRAVEYARD, filter);
if (controller.choose(Outcome.Exile, targetPlayer.getGraveyard(), target, game)) {
controller.moveCards(new CardsImpl(target.getTargets()), Zone.EXILED, source, game);
}
}
// cards in Hand
int numberOfCardsExiledFromHand = 0;
cardsCount = (cardName.isEmpty() ? 0 : targetPlayer.getHand().count(filter, game));
if (cardsCount > 0) {
filter.setMessage("card named " + cardName + " in the hand of " + targetPlayer.getName());
TargetCard target = new TargetCard(0, cardsCount, Zone.HAND, filter);
if (controller.choose(Outcome.Exile, targetPlayer.getHand(), target, game)) {
numberOfCardsExiledFromHand = target.getTargets().size();
controller.moveCards(new CardsImpl(target.getTargets()), Zone.EXILED, source, game);
}
} else {
targetPlayer.revealCards(targetPlayer.getName() + "'s Hand", targetPlayer.getHand(), game);
}
// cards in Library
Cards cardsInLibrary = new CardsImpl();
cardsInLibrary.addAll(targetPlayer.getLibrary().getCards(game));
cardsCount = (cardName.isEmpty() ? 0 : cardsInLibrary.count(filter, game));
if (cardsCount > 0) {
filter.setMessage("card named " + cardName + " in the library of " + targetPlayer.getLogName());
TargetCardInLibrary targetLib = new TargetCardInLibrary(0, cardsCount, filter);
if (controller.choose(Outcome.Exile, cardsInLibrary, targetLib, game)) {
controller.moveCards(new CardsImpl(targetLib.getTargets()), Zone.EXILED, source, game);
}
} else {
targetPlayer.revealCards(targetPlayer.getName() + "'s Library", new CardsImpl(new HashSet<>(targetPlayer.getLibrary().getCards(game))), game);
}
targetPlayer.shuffleLibrary(source, game);
if (numberOfCardsExiledFromHand > 0) {
game.getState().applyEffects(game);
Token zombieToken = new ZombieToken();
zombieToken.putOntoBattlefield(numberOfCardsExiledFromHand, game, source, targetPlayer.getId());
}
return true;
}
return false;
}
use of mage.filter.FilterCard in project mage by magefree.
the class RansackEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getFirstTarget());
FilterCard filter = new FilterCard("cards to put on the bottom of your library");
if (player != null) {
int number = min(player.getLibrary().size(), 5);
Set<Card> cards = player.getLibrary().getTopCards(game, number);
Cards cardsRemaining = new CardsImpl();
cardsRemaining.addAll(cards);
TargetCard target = new TargetCard(0, number, Zone.LIBRARY, filter);
if (player.choose(Outcome.DrawCard, cardsRemaining, target, game)) {
Cards pickedCards = new CardsImpl(target.getTargets());
cardsRemaining.removeAll(pickedCards);
player.putCardsOnBottomOfLibrary(pickedCards, game, source, true);
player.putCardsOnTopOfLibrary(cardsRemaining, game, source, true);
return true;
}
}
return false;
}
use of mage.filter.FilterCard in project mage by magefree.
the class SkullsnatcherTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (((DamagedPlayerEvent) event).isCombatDamage() && event.getSourceId().equals(sourceId)) {
FilterCard filter = new FilterCard("up to two target cards from that player's graveyard");
filter.add(new OwnerIdPredicate(event.getPlayerId()));
filter.setMessage("up to two cards in " + game.getPlayer(event.getTargetId()).getLogName() + "'s graveyard");
this.getTargets().clear();
this.addTarget(new TargetCardInOpponentsGraveyard(0, 2, filter));
return true;
}
return false;
}
Aggregations