Search in sources :

Example 86 with TargetCardInLibrary

use of mage.target.common.TargetCardInLibrary in project mage by magefree.

the class DistantMemoriesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    TargetCardInLibrary target = new TargetCardInLibrary();
    if (controller.searchLibrary(target, source, game)) {
        Card card = controller.getLibrary().remove(target.getFirstTarget(), game);
        if (card != null) {
            controller.moveCards(card, Zone.EXILED, source, game);
            controller.shuffleLibrary(source, game);
            StringBuilder sb = new StringBuilder();
            sb.append("Have ").append(controller.getLogName()).append(" put ").append(card.getName());
            sb.append(" in their hand? If none of their opponents says yes, they will draw three cards.");
            boolean putInHand = false;
            Set<UUID> opponents = game.getOpponents(source.getControllerId());
            for (UUID opponentUuid : opponents) {
                Player opponent = game.getPlayer(opponentUuid);
                if (opponent != null) {
                    if (opponent.chooseUse(Outcome.Detriment, sb.toString(), source, game)) {
                        putInHand = true;
                        game.informPlayers(opponent.getLogName() + " decides to put the selected card into the player's hand.");
                    } else {
                        game.informPlayers(opponent.getLogName() + " decides to leave the card in exile.");
                    }
                }
            }
            if (putInHand) {
                controller.moveCards(card, Zone.HAND, source, game);
            } else {
                controller.drawCards(3, source, game);
            }
            return true;
        }
    }
    controller.shuffleLibrary(source, game);
    return false;
}
Also used : Player(mage.players.Player) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card)

Example 87 with TargetCardInLibrary

use of mage.target.common.TargetCardInLibrary in project mage by magefree.

the class EmergentUltimatumTarget method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    TargetCardInLibrary targetCardInLibrary = new EmergentUltimatumTarget();
    targetCardInLibrary.setNotTarget(true);
    boolean searched = player.searchLibrary(targetCardInLibrary, source, game);
    Cards cards = new CardsImpl(targetCardInLibrary.getTargets());
    player.moveCards(cards, Zone.EXILED, source, game);
    if (cards.isEmpty()) {
        if (searched) {
            player.shuffleLibrary(source, game);
        }
        return false;
    }
    TargetOpponent targetOpponent = new TargetOpponent();
    targetOpponent.setNotTarget(true);
    player.choose(outcome, targetOpponent, source.getSourceId(), game);
    Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
    if (opponent == null) {
        if (searched) {
            player.shuffleLibrary(source, game);
        }
        return false;
    }
    TargetCardInExile targetCardInExile = new TargetCardInExile(StaticFilters.FILTER_CARD);
    targetCardInExile.setNotTarget(true);
    opponent.choose(outcome, cards, targetCardInExile, game);
    Card toShuffle = game.getCard(targetCardInExile.getFirstTarget());
    if (toShuffle != null) {
        player.putCardsOnBottomOfLibrary(toShuffle, game, source, false);
        player.shuffleLibrary(source, game);
        cards.remove(toShuffle);
    }
    while (!cards.isEmpty()) {
        if (!player.chooseUse(Outcome.PlayForFree, "Cast an exiled card without paying its mana cost?", source, game)) {
            break;
        }
        targetCardInExile.clearChosen();
        if (!player.choose(Outcome.PlayForFree, cards, targetCardInExile, game)) {
            continue;
        }
        Card card = game.getCard(targetCardInExile.getFirstTarget());
        if (card == null) {
            continue;
        }
        game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
        Boolean cardWasCast = player.cast(player.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
        game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
        // remove on non cast too (infinite freeze fix)
        cards.remove(card);
        if (cardWasCast) {
            cards.remove(card);
        } else {
            game.informPlayer(player, "You're not able to cast " + card.getIdName() + " or you canceled the casting.");
        }
    }
    return true;
}
Also used : Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) ApprovingObject(mage.ApprovingObject) TargetCardInExile(mage.target.common.TargetCardInExile) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard)

Example 88 with TargetCardInLibrary

use of mage.target.common.TargetCardInLibrary in project mage by magefree.

the class EmergentSequenceWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    // put land
    TargetCardInLibrary target = new TargetCardInLibrary(StaticFilters.FILTER_CARD_BASIC_LAND_A);
    player.searchLibrary(target, source, game);
    Card card = player.getLibrary().getCard(target.getFirstTarget(), game);
    Permanent permanent = null;
    if (card != null) {
        player.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
        permanent = game.getPermanent(target.getFirstTarget());
    }
    player.shuffleLibrary(source, game);
    if (permanent == null) {
        return true;
    }
    // boost land
    game.addEffect(new BecomesCreatureTargetEffect(new FractalToken(), false, true, Duration.Custom).setTargetPointer(new FixedTarget(permanent, game)), source);
    // rules
    // The last sentence of Emergent Sequence’s ability counts the land it put onto the battlefield.
    // (2021-04-16)
    // no ETB yet, so add +1 manually
    int amount = 1 + EmergentSequenceWatcher.getAmount(source.getControllerId(), game);
    permanent.addCounters(CounterType.P1P1.createInstance(amount), source.getControllerId(), source, game);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) FractalToken(mage.game.permanent.token.FractalToken) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) BecomesCreatureTargetEffect(mage.abilities.effects.common.continuous.BecomesCreatureTargetEffect) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Hint(mage.abilities.hint.Hint) Card(mage.cards.Card)

Example 89 with TargetCardInLibrary

use of mage.target.common.TargetCardInLibrary in project mage by magefree.

the class GhostQuarterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
    if (permanent != null) {
        Player controller = game.getPlayer(permanent.getControllerId());
        if (controller != null && controller.chooseUse(Outcome.PutLandInPlay, "Search for a basic land, put it onto the battlefield, and then shuffle?", source, game)) {
            TargetCardInLibrary target = new TargetCardInLibrary(StaticFilters.FILTER_CARD_BASIC_LAND);
            if (controller.searchLibrary(target, source, game)) {
                Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
                if (card != null) {
                    controller.moveCards(card, Zone.BATTLEFIELD, source, game);
                }
            }
            controller.shuffleLibrary(source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) TargetLandPermanent(mage.target.common.TargetLandPermanent) Permanent(mage.game.permanent.Permanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card)

Example 90 with TargetCardInLibrary

use of mage.target.common.TargetCardInLibrary in project mage by magefree.

the class HibernationsEndEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (sourcePermanent != null && player != null) {
        int newConvertedCost = sourcePermanent.getCounters(game).getCount("age");
        FilterCard filter = new FilterCard("creature card with mana value " + newConvertedCost);
        filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, newConvertedCost));
        filter.add(CardType.CREATURE.getPredicate());
        TargetCardInLibrary target = new TargetCardInLibrary(filter);
        return new SearchLibraryPutInPlayEffect(target).apply(game, source);
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Permanent(mage.game.permanent.Permanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) SearchLibraryPutInPlayEffect(mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect)

Aggregations

TargetCardInLibrary (mage.target.common.TargetCardInLibrary)225 Player (mage.players.Player)207 FilterCard (mage.filter.FilterCard)120 Card (mage.cards.Card)110 Permanent (mage.game.permanent.Permanent)68 UUID (java.util.UUID)65 CardsImpl (mage.cards.CardsImpl)53 TargetCard (mage.target.TargetCard)53 MageObject (mage.MageObject)37 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)31 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)28 Cards (mage.cards.Cards)26 TargetPlayer (mage.target.TargetPlayer)19 FilterCreatureCard (mage.filter.common.FilterCreatureCard)18 FilterPermanent (mage.filter.FilterPermanent)14 TargetPermanent (mage.target.TargetPermanent)14 FixedTarget (mage.target.targetpointer.FixedTarget)14 Cost (mage.abilities.costs.Cost)13 SearchLibraryPutInHandEffect (mage.abilities.effects.common.search.SearchLibraryPutInHandEffect)13 SearchLibraryPutInPlayEffect (mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect)12