Search in sources :

Example 66 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class AugustaDeanOfOrderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    boolean cardWasCast = false;
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null && controller.getLibrary().hasCards()) {
        CardsImpl toReveal = new CardsImpl();
        Card eligibleCard = null;
        for (Card card : controller.getLibrary().getCards(game)) {
            toReveal.add(card);
            if (!card.isLand(game) && !card.isLegendary() && card.getManaValue() < 4) {
                eligibleCard = card;
                break;
            }
        }
        controller.revealCards(source, toReveal, game);
        if (eligibleCard != null && controller.chooseUse(Outcome.PlayForFree, "Cast " + eligibleCard.getLogName() + " without paying its mana cost?", source, game)) {
            game.getState().setValue("PlayFromNotOwnHandZone" + eligibleCard.getId(), Boolean.TRUE);
            cardWasCast = controller.cast(controller.chooseAbilityForCast(eligibleCard, game, true), game, true, new ApprovingObject(source, game));
            game.getState().setValue("PlayFromNotOwnHandZone" + eligibleCard.getId(), null);
            if (cardWasCast) {
                toReveal.remove(eligibleCard);
            }
        }
        controller.putCardsOnBottomOfLibrary(toReveal, game, source, false);
    }
    return cardWasCast;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard)

Example 67 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class TargetYouPredicate method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && sourcePermanent != null) {
        TargetCardInExile target = new TargetCardInExile(new FilterCard(), CardUtil.getExileZoneId(game, source.getSourceId(), sourcePermanent.getZoneChangeCounter(game)));
        if (controller.choose(Outcome.PlayForFree, game.getExile().getExileZone(CardUtil.getExileZoneId(game, source.getSourceId(), sourcePermanent.getZoneChangeCounter(game))), target, game)) {
            Card card = game.getCard(target.getFirstTarget());
            if (card != null && controller.chooseUse(outcome, "Cast " + card.getLogName() + " 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 cardWasCast;
            }
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ObjectSourcePlayer(mage.filter.predicate.ObjectSourcePlayer) ApprovingObject(mage.ApprovingObject) Permanent(mage.game.permanent.Permanent) TargetCardInExile(mage.target.common.TargetCardInExile) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 68 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class TwinningGlassEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<Spell> spells = new ArrayList<>();
    Permanent twinningGlass = game.getPermanent(source.getSourceId());
    Player controller = game.getPlayer(source.getControllerId());
    SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
    if (twinningGlass == null) {
        twinningGlass = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
    }
    if (twinningGlass != null && controller != null && watcher != null) {
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            if (watcher.getSpellsCastThisTurn(playerId) != null) {
                for (Spell spell : watcher.getSpellsCastThisTurn(playerId)) {
                    spells.add(spell);
                }
            }
        }
        if (spells.isEmpty()) {
            return false;
        }
        List<NamePredicate> predicates = spells.stream().map(Spell::getName).filter(Objects::nonNull).filter(s -> !s.isEmpty()).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);
        target.withChooseHint("free cast");
        if (controller.choose(Outcome.PlayForFree, controller.getHand(), target, game)) {
            Card chosenCard = game.getCard(target.getFirstTarget());
            if (chosenCard != null) {
                game.getState().setValue("PlayFromNotOwnHandZone" + chosenCard.getId(), Boolean.TRUE);
                Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(chosenCard, game, true), game, true, new ApprovingObject(source, game));
                game.getState().setValue("PlayFromNotOwnHandZone" + chosenCard.getId(), null);
                return cardWasCast;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) ApprovingObject(mage.ApprovingObject) Permanent(mage.game.permanent.Permanent) ArrayList(java.util.ArrayList) TargetCard(mage.target.TargetCard) Spell(mage.game.stack.Spell) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterNonlandCard(mage.filter.common.FilterNonlandCard) SpellsCastWatcher(mage.watchers.common.SpellsCastWatcher) UUID(java.util.UUID)

Example 69 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class YennettCrypticSovereignEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null || !player.getLibrary().hasCards()) {
        return false;
    }
    Card card = player.getLibrary().getFromTop(game);
    if (card == null) {
        return false;
    }
    player.revealCards(source, new CardsImpl(card), game);
    if (card.getManaValue() % 2 == 1) {
        if (player.chooseUse(outcome, "Cast " + card.getLogName() + " without paying its mana cost?", source, game)) {
            game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
            player.cast(player.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
            game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
        } else {
            /*
                7/13/2018 | If the revealed card doesn’t have an odd converted mana cost or if that card does but you 
                choose not to cast it, you draw a card. Keep in mind that revealing a card doesn’t cause it to change 
                zones. This means that the card you draw will be the card you revealed.
                 */
            player.drawCards(1, source, game);
        }
    } else {
        player.drawCards(1, source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 70 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class JaceMindseekerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Cards cardsToCast = new CardsImpl();
    Player targetOpponent = game.getPlayer(targetPointer.getFirst(game, source));
    if (targetOpponent != null) {
        Set<Card> allCards = targetOpponent.millCards(5, source, game).getCards(game);
        for (Card card : allCards) {
            if (filter.match(card, game)) {
                Zone zone = game.getState().getZone(card.getId());
                // you can cast one of those instant or sorcery cards from that zone.
                if (zone == Zone.GRAVEYARD || zone == Zone.EXILED) {
                    cardsToCast.add(card);
                }
            }
        }
        // cast an instant or sorcery for free
        if (!cardsToCast.isEmpty()) {
            Player controller = game.getPlayer(source.getControllerId());
            if (controller != null) {
                // zone should be ignored here
                TargetCard target = new TargetCard(Zone.GRAVEYARD, filter);
                target.setNotTarget(true);
                if (controller.chooseUse(outcome, "Cast an instant or sorcery card from among them for free?", source, game) && controller.choose(Outcome.PlayForFree, cardsToCast, target, game)) {
                    Card card = cardsToCast.get(target.getFirstTarget(), game);
                    if (card != null) {
                        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);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) Zone(mage.constants.Zone) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard)

Aggregations

ApprovingObject (mage.ApprovingObject)111 Player (mage.players.Player)109 Card (mage.cards.Card)77 FilterCard (mage.filter.FilterCard)53 TargetCard (mage.target.TargetCard)30 MageObject (mage.MageObject)20 FilterInstantOrSorceryCard (mage.filter.common.FilterInstantOrSorceryCard)17 CardsImpl (mage.cards.CardsImpl)16 Permanent (mage.game.permanent.Permanent)16 UUID (java.util.UUID)15 TargetCardInHand (mage.target.common.TargetCardInHand)13 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)11 FilterNonlandCard (mage.filter.common.FilterNonlandCard)10 TargetCardInExile (mage.target.common.TargetCardInExile)10 ExileZone (mage.game.ExileZone)9 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)9 Cards (mage.cards.Cards)8 Spell (mage.game.stack.Spell)8 Target (mage.target.Target)7 FixedTarget (mage.target.targetpointer.FixedTarget)7