Search in sources :

Example 1 with Library

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

the class TransmogrifyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
    if (permanent != null) {
        Player player = game.getPlayer(permanent.getControllerId());
        if (player != null) {
            Library library = player.getLibrary();
            if (library.hasCards()) {
                Cards cards = new CardsImpl();
                Card toBattlefield = null;
                for (Card card : library.getCards(game)) {
                    cards.add(card);
                    if (card.isCreature(game)) {
                        toBattlefield = card;
                        break;
                    }
                }
                if (toBattlefield != null) {
                    player.moveCards(toBattlefield, Zone.BATTLEFIELD, source, game);
                }
                player.revealCards(source, cards, game);
                cards.remove(toBattlefield);
                if (!cards.isEmpty()) {
                    player.shuffleLibrary(source, game);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Library(mage.players.Library)

Example 2 with Library

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

the class ReweaveEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
    MageObject sourceObject = source.getSourceObject(game);
    if (permanent != null && sourceObject != null) {
        if (permanent.sacrifice(source, game)) {
            Player permanentController = game.getPlayer(permanent.getControllerId());
            if (permanentController != null) {
                Library library = permanentController.getLibrary();
                if (library.hasCards()) {
                    Cards cards = new CardsImpl();
                    Card permanentCard = null;
                    for (Card card : permanentController.getLibrary().getCards(game)) {
                        cards.add(card);
                        if (card.isPermanent(game)) {
                            for (CardType cardType : permanent.getCardType(game)) {
                                if (card.getCardType(game).contains(cardType)) {
                                    permanentCard = card;
                                    break;
                                }
                            }
                        }
                    }
                    permanentController.revealCards(source, cards, game);
                    if (permanentCard != null) {
                        permanentController.moveCards(permanentCard, Zone.BATTLEFIELD, source, game);
                    }
                    permanentController.shuffleLibrary(source, game);
                }
                return true;
            }
            return false;
        }
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) CardType(mage.constants.CardType) MageObject(mage.MageObject) Library(mage.players.Library) FilterPermanentCard(mage.filter.common.FilterPermanentCard)

Example 3 with Library

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

the class KnacksawCliqueCastFromExileEffect 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 KnacksawCliqueCastFromExileEffect();
                effect.setTargetPointer(new FixedTarget(card.getId(), game));
                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 4 with Library

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

the class KillerInstinctEffect 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 == null) {
        return false;
    }
    Library library = player.getLibrary();
    if (library == null || !library.hasCards()) {
        return false;
    }
    Card card = library.getFromTop(game);
    if (card == null) {
        return false;
    }
    player.revealCards(sourceObject.getIdName(), new CardsImpl(card), game);
    if (card.isCreature(game) && player.moveCards(card, Zone.BATTLEFIELD, source, game)) {
        Permanent permanent = game.getPermanent(card.getId());
        if (permanent != null) {
            FixedTarget ft = new FixedTarget(permanent, game);
            ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
            effect.setTargetPointer(ft);
            game.addEffect(effect, source);
            Effect sacrificeEffect = new SacrificeTargetEffect("Sacrifice it at the beginning of the next end step", source.getControllerId());
            sacrificeEffect.setTargetPointer(ft);
            game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(sacrificeEffect), source);
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) SacrificeTargetEffect(mage.abilities.effects.common.SacrificeTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) Library(mage.players.Library) ContinuousEffect(mage.abilities.effects.ContinuousEffect) SacrificeTargetEffect(mage.abilities.effects.common.SacrificeTargetEffect) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 5 with Library

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

the class NicolBolasGodPharaohPlusTwoEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
    if (opponent == null) {
        return false;
    }
    Library library = opponent.getLibrary();
    Card card;
    do {
        card = library.getFromTop(game);
        if (card == null) {
            continue;
        }
        opponent.moveCards(card, Zone.EXILED, source, game);
        if (card.isLand(game)) {
            continue;
        }
        ContinuousEffect effect = new PlayFromNotOwnHandZoneTargetEffect(Zone.EXILED, TargetController.YOU, Duration.EndOfTurn, true);
        effect.setTargetPointer(new FixedTarget(card, game));
        game.addEffect(effect, source);
        break;
    } while (library.hasCards() && card != null);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) PlayFromNotOwnHandZoneTargetEffect(mage.abilities.effects.common.asthought.PlayFromNotOwnHandZoneTargetEffect) Library(mage.players.Library) ContinuousEffect(mage.abilities.effects.ContinuousEffect) FilterCard(mage.filter.FilterCard)

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