Search in sources :

Example 76 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class SproutbackTrudgeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObjectIfItStillExists(game);
    if (player == null || !(sourceObject instanceof Card)) {
        return false;
    }
    Card card = (Card) sourceObject;
    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
    player.cast(player.chooseAbilityForCast(card, game, false), game, false, new ApprovingObject(source, game));
    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
    return true;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) MageObject(mage.MageObject) Card(mage.cards.Card)

Example 77 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class SunbirdsInvocationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller == null || sourceObject == null) {
        return false;
    }
    Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source));
    if (spell == null) {
        return false;
    }
    int xValue = spell.getManaValue();
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, xValue));
    if (!cards.isEmpty()) {
        controller.revealCards(sourceObject.getIdName(), cards, game);
        FilterCard filter = new FilterNonlandCard("card revealed this way with mana value " + xValue + " or less");
        filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
        TargetCard target = new TargetCard(1, Zone.LIBRARY, filter);
        if (controller.chooseTarget(Outcome.PlayForFree, cards, target, source, game)) {
            Card card = cards.get(target.getFirstTarget(), game);
            if (card != null) {
                if (controller.chooseUse(Outcome.Benefit, "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);
                    if (cardWasCast) {
                        cards.remove(card);
                    }
                }
            }
        }
        controller.putCardsOnBottomOfLibrary(cards, game, source, false);
    }
    return true;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) Spell(mage.game.stack.Spell) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterNonlandCard(mage.filter.common.FilterNonlandCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 78 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class TibaltsTrickeryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source));
    if (spell != null) {
        String spellName = spell.getName();
        Player controller = game.getPlayer(spell.getControllerId());
        game.getStack().counter(spell.getId(), source, game);
        if (controller != null) {
            int random = RandomUtil.nextInt(3) + 1;
            game.informPlayers(random + " was chosen at random");
            controller.millCards(random, source, game);
            Card cardToCast = null;
            Set<Card> cardsToExile = new HashSet<>();
            FilterCard filter = new FilterCard();
            filter.add(Predicates.not(CardType.LAND.getPredicate()));
            filter.add(Predicates.not(new NamePredicate(spellName)));
            for (Card card : controller.getLibrary().getCards(game)) {
                cardsToExile.add(card);
                if (filter.match(card, game)) {
                    cardToCast = card;
                    break;
                }
            }
            controller.moveCardsToExile(cardsToExile, source, game, true, source.getSourceId(), CardUtil.createObjectRealtedWindowTitle(source, game, null));
            if (cardToCast != null) {
                if (controller.chooseUse(Outcome.PlayForFree, "Cast " + cardToCast.getLogName() + " for free?", source, game)) {
                    game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), Boolean.TRUE);
                    controller.cast(controller.chooseAbilityForCast(cardToCast, game, true), game, true, new ApprovingObject(source, game));
                    game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), null);
                }
            }
            ExileZone exile = game.getExile().getExileZone(source.getSourceId());
            if (exile != null) {
                controller.putCardsOnBottomOfLibrary(exile, game, source, false);
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) ApprovingObject(mage.ApprovingObject) ExileZone(mage.game.ExileZone) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card) HashSet(java.util.HashSet)

Example 79 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class TreasureKeeperEffect 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 nonLandCard = null;
        for (Card card : controller.getLibrary().getCards(game)) {
            toReveal.add(card);
            if (!card.isLand(game) && card.getManaValue() < 4) {
                nonLandCard = card;
                break;
            }
        }
        controller.revealCards(source, toReveal, game);
        if (nonLandCard != null && controller.chooseUse(Outcome.PlayForFree, "Cast " + nonLandCard.getLogName() + " without paying its mana cost?", source, game)) {
            game.getState().setValue("PlayFromNotOwnHandZone" + nonLandCard.getId(), Boolean.TRUE);
            cardWasCast = controller.cast(controller.chooseAbilityForCast(nonLandCard, game, true), game, true, new ApprovingObject(source, game));
            game.getState().setValue("PlayFromNotOwnHandZone" + nonLandCard.getId(), null);
            if (cardWasCast) {
                toReveal.remove(nonLandCard);
            }
        }
        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)

Example 80 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class UnpredictableCycloneReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Player player = game.getPlayer(event.getPlayerId());
    StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
    if (player == null || stackObject == null) {
        return false;
    }
    Card sourceCard = game.getCard(stackObject.getSourceId());
    if (sourceCard == null) {
        return false;
    }
    Cards cards = new CardsImpl();
    Card toCast = null;
    for (Card card : player.getLibrary().getCards(game)) {
        cards.add(card);
        if (card.getCardType(game).stream().anyMatch(sourceCard.getCardType(game)::contains)) {
            toCast = card;
            break;
        }
    }
    player.moveCards(cards, Zone.EXILED, source, game);
    if (toCast != null && player.chooseUse(outcome, "Cast the exiled card?", source, game)) {
        game.getState().setValue("PlayFromNotOwnHandZone" + toCast.getId(), Boolean.TRUE);
        Boolean cardWasCast = player.cast(player.chooseAbilityForCast(toCast, game, true), game, true, new ApprovingObject(source, game));
        game.getState().setValue("PlayFromNotOwnHandZone" + toCast.getId(), null);
        if (cardWasCast) {
            cards.remove(toCast);
        }
    }
    player.putCardsOnBottomOfLibrary(cards, game, source, false);
    return true;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) StackObject(mage.game.stack.StackObject)

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