Search in sources :

Example 6 with Library

use of mage.players.Library in project mage by magefree.

the class ChandraTorchOfDefianceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null && controller.getLibrary().hasCards()) {
        Library library = controller.getLibrary();
        Card card = library.getFromTop(game);
        if (card != null) {
            boolean cardWasCast = false;
            controller.moveCardsToExile(card, source, game, true, source.getSourceId(), sourceObject.getIdName());
            if (!card.getManaCost().isEmpty() || !card.isLand(game)) {
                if (controller.chooseUse(Outcome.Benefit, "Cast " + card.getName() + "? (You still pay the costs)", source, game) && (game.getState().getZone(card.getId()) == Zone.EXILED)) {
                    // card must be in the exile zone
                    // enable the card to be cast from the exile zone
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                    cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, false), game, false, new ApprovingObject(source, game));
                    // reset to null
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
                }
            }
            if (!cardWasCast) {
                new DamagePlayersEffect(Outcome.Damage, StaticValue.get(2), TargetController.OPPONENT).apply(game, source);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) MageObject(mage.MageObject) Library(mage.players.Library) DamagePlayersEffect(mage.abilities.effects.common.DamagePlayersEffect) Card(mage.cards.Card)

Example 7 with Library

use of mage.players.Library in project mage by magefree.

the class NivixAerieOfTheFiremindCanCastEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Library library = controller.getLibrary();
        if (library.hasCards()) {
            Card card = library.getFromTop(game);
            if (card != null && controller.moveCardsToExile(card, source, game, true, source.getSourceId(), CardUtil.createObjectRealtedWindowTitle(source, game, null)) && card.isInstantOrSorcery(game)) {
                ContinuousEffect effect = new NivixAerieOfTheFiremindCanCastEffect();
                effect.setTargetPointer(new FixedTarget(card.getId()));
                game.addEffect(effect, source);
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Library(mage.players.Library) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Card(mage.cards.Card)

Example 8 with Library

use of mage.players.Library in project mage by magefree.

the class OrnateKanzashiCastFromExileEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (sourceObject != null && opponent != null) {
        if (opponent.getLibrary().hasCards()) {
            Library library = opponent.getLibrary();
            Card card = library.getFromTop(game);
            if (card != null) {
                opponent.moveCardToExileWithInfo(card, source.getSourceId(), sourceObject.getName(), source, game, Zone.LIBRARY, true);
                ContinuousEffect effect = new OrnateKanzashiCastFromExileEffect();
                effect.setTargetPointer(new FixedTarget(card.getId()));
                game.addEffect(effect, source);
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) MageObject(mage.MageObject) Library(mage.players.Library) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Card(mage.cards.Card)

Example 9 with Library

use of mage.players.Library in project mage by magefree.

the class RevealCardsFromLibraryUntilEffect 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 || !controller.getLibrary().hasCards()) {
        return false;
    }
    Cards cards = new CardsImpl();
    Library library = controller.getLibrary();
    Card card = null;
    do {
        card = library.removeFromTop(game);
        if (card != null) {
            cards.add(card);
        }
    } while (library.hasCards() && !filter.match(card, game));
    // reveal cards
    if (cards.isEmpty()) {
        return true;
    }
    controller.revealCards(sourceObject.getIdName(), cards, game);
    if (filter.match(card, game)) {
        // put card in correct zone
        controller.moveCards(card, zoneToPutCard, source, game);
        // remove it from revealed card list
        cards.remove(card);
    }
    // Put the rest in correct zone
    if (zoneToPutRest == Zone.LIBRARY) {
        if (!cards.isEmpty()) {
            if (shuffleRestInto) {
                library.addAll(cards.getCards(game), game);
            } else {
                controller.putCardsOnBottomOfLibrary(cards, game, source, anyOrder);
            }
        }
    } else {
        if (!cards.isEmpty()) {
            controller.moveCards(cards, zoneToPutRest, source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) Library(mage.players.Library) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 10 with Library

use of mage.players.Library in project mage by magefree.

the class IndomitableCreativityEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        List<Permanent> destroyedPermanents = new ArrayList<>();
        for (UUID targetId : getTargetPointer().getTargets(game, source)) {
            Permanent target = game.getPermanent(targetId);
            if (target != null) {
                if (target.destroy(source, game, false)) {
                    destroyedPermanents.add(target);
                }
            }
        }
        for (Permanent permanent : destroyedPermanents) {
            Player controllerOfDestroyedCreature = game.getPlayer(permanent.getControllerId());
            if (controllerOfDestroyedCreature != null) {
                Library library = controllerOfDestroyedCreature.getLibrary();
                if (library.hasCards()) {
                    Cards cardsToReaveal = new CardsImpl();
                    for (Card card : library.getCards(game)) {
                        cardsToReaveal.add(card);
                        if (card.isCreature(game) || card.isArtifact(game)) {
                            controllerOfDestroyedCreature.moveCards(card, Zone.EXILED, source, game);
                            controllerOfDestroyedCreature.moveCards(card, Zone.BATTLEFIELD, source, game);
                            break;
                        }
                    }
                    controllerOfDestroyedCreature.revealCards(source, " for destroyed " + permanent.getIdName(), cardsToReaveal, game);
                    controllerOfDestroyedCreature.shuffleLibrary(source, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ArrayList(java.util.ArrayList) Library(mage.players.Library) UUID(java.util.UUID)

Aggregations

Library (mage.players.Library)18 Player (mage.players.Player)18 Card (mage.cards.Card)11 MageObject (mage.MageObject)9 Permanent (mage.game.permanent.Permanent)7 ContinuousEffect (mage.abilities.effects.ContinuousEffect)5 CardsImpl (mage.cards.CardsImpl)5 FixedTarget (mage.target.targetpointer.FixedTarget)5 UUID (java.util.UUID)3 Cards (mage.cards.Cards)3 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)3 ApprovingObject (mage.ApprovingObject)2 CardType (mage.constants.CardType)2 FilterCard (mage.filter.FilterCard)2 TargetPermanent (mage.target.TargetPermanent)2 ArrayList (java.util.ArrayList)1 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)1 Effect (mage.abilities.effects.Effect)1 OneShotEffect (mage.abilities.effects.OneShotEffect)1 DamagePlayersEffect (mage.abilities.effects.common.DamagePlayersEffect)1