Search in sources :

Example 11 with Library

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

the class PossibilityStormEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source));
    // spell was exiled already by another effect, for example NivMagus Elemental
    boolean noLongerOnStack = false;
    if (spell == null) {
        spell = ((Spell) game.getLastKnownInformation(targetPointer.getFirst(game, source), Zone.STACK));
        noLongerOnStack = true;
    }
    MageObject sourceObject = source.getSourceObject(game);
    if (sourceObject != null && spell != null) {
        Player spellController = game.getPlayer(spell.getControllerId());
        if (spellController != null) {
            if (!noLongerOnStack) {
                spellController.moveCardsToExile(spell, source, game, true, source.getSourceId(), sourceObject.getIdName());
            }
            if (spellController.getLibrary().hasCards()) {
                Library library = spellController.getLibrary();
                Card card;
                do {
                    card = library.getFromTop(game);
                    if (card != null) {
                        spellController.moveCardsToExile(card, source, game, true, source.getSourceId(), sourceObject.getIdName());
                    }
                } while (library.hasCards() && card != null && !sharesType(card, spell.getCardType(game), game));
                if (card != null && sharesType(card, spell.getCardType(game), game) && !card.isLand(game) && card.getSpellAbility().canChooseTarget(game, spellController.getId())) {
                    if (spellController.chooseUse(Outcome.PlayForFree, "Cast " + card.getLogName() + " without paying cost?", source, game)) {
                        game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                        spellController.cast(spellController.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                        game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
                    }
                }
                ExileZone exile = game.getExile().getExileZone(source.getSourceId());
                if (exile != null) {
                    spellController.putCardsOnBottomOfLibrary(exile, game, source, false);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) MageObject(mage.MageObject) ExileZone(mage.game.ExileZone) Library(mage.players.Library) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Example 12 with Library

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

the class PolymorphEffect 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) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 13 with Library

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

the class VigeanIntuitionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject sourceObject = game.getObject(source.getSourceId());
    Player player = game.getPlayer(source.getControllerId());
    if (sourceObject == null || player == null) {
        return false;
    }
    Library library = player.getLibrary();
    if (library == null) {
        return false;
    }
    Choice choiceImpl = new ChoiceImpl();
    choiceImpl.setChoices(choice);
    if (player.choose(Outcome.Neutral, choiceImpl, game)) {
        String choosenType = choiceImpl.getChoice();
        if (choosenType == null || choosenType.isEmpty()) {
            return false;
        }
        CardType type = null;
        if (choosenType.equals(CardType.ARTIFACT.toString())) {
            type = CardType.ARTIFACT;
        } else if (choosenType.equals(CardType.LAND.toString())) {
            type = CardType.LAND;
        } else if (choosenType.equals(CardType.CREATURE.toString())) {
            type = CardType.CREATURE;
        } else if (choosenType.equals(CardType.ENCHANTMENT.toString())) {
            type = CardType.ENCHANTMENT;
        } else if (choosenType.equals(CardType.INSTANT.toString())) {
            type = CardType.INSTANT;
        } else if (choosenType.equals(CardType.SORCERY.toString())) {
            type = CardType.SORCERY;
        } else if (choosenType.equals(CardType.PLANESWALKER.toString())) {
            type = CardType.PLANESWALKER;
        } else if (choosenType.equals(CardType.TRIBAL.toString())) {
            type = CardType.TRIBAL;
        }
        if (type != null) {
            Set<Card> top = library.getTopCards(game, 4);
            player.revealCards(source, new CardsImpl(top), game);
            Cards putInHand = new CardsImpl();
            Cards putInGraveyard = new CardsImpl();
            for (Card card : top) {
                if (card != null && card.getCardType(game).contains(type)) {
                    putInHand.add(card);
                } else {
                    putInGraveyard.add(card);
                }
            }
            player.moveCards(putInHand, Zone.HAND, source, game);
            player.moveCards(putInGraveyard, Zone.GRAVEYARD, source, game);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) CardType(mage.constants.CardType) MageObject(mage.MageObject) ChoiceImpl(mage.choices.ChoiceImpl) Library(mage.players.Library)

Example 14 with Library

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

the class ExplosiveRevelationEffect 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) {
        if (controller.getLibrary().hasCards()) {
            CardsImpl toReveal = new CardsImpl();
            Library library = controller.getLibrary();
            Card nonLandCard = null;
            for (Card card : library.getCards(game)) {
                toReveal.add(card);
                if (!card.isLand(game)) {
                    nonLandCard = card;
                    break;
                }
            }
            // reveal cards
            controller.revealCards(sourceObject.getIdName(), toReveal, game);
            // the nonland card
            int damage = nonLandCard == null ? 0 : nonLandCard.getManaValue();
            // assign damage to target
            for (UUID targetId : targetPointer.getTargets(game, source)) {
                Permanent targetedCreature = game.getPermanent(targetId);
                if (targetedCreature != null) {
                    targetedCreature.damage(damage, source.getSourceId(), source, game, false, true);
                } else {
                    Player targetedPlayer = game.getPlayer(targetId);
                    if (targetedPlayer != null) {
                        targetedPlayer.damage(damage, source.getSourceId(), source, game);
                    }
                }
            }
            if (nonLandCard != null) {
                // move nonland card to hand
                controller.moveCards(nonLandCard, Zone.HAND, source, game);
                toReveal.remove(nonLandCard);
            }
            // put the rest of the cards on the bottom of the library in any order
            return controller.putCardsOnBottomOfLibrary(toReveal, game, source, true);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) Library(mage.players.Library) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 15 with Library

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

the class BlessedReincarnationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (permanent != null && controller != null) {
        controller.moveCards(permanent, Zone.EXILED, source, game);
        game.getState().processAction(game);
        Player permanentController = game.getPlayer(permanent.getControllerId());
        if (permanentController != null) {
            Library library = permanentController.getLibrary();
            if (library.hasCards()) {
                Cards toReveal = new CardsImpl();
                for (Card card : library.getCards(game)) {
                    toReveal.add(card);
                    if (card.isCreature(game)) {
                        permanentController.moveCards(card, Zone.BATTLEFIELD, source, game);
                        break;
                    }
                }
                permanentController.revealCards(source, toReveal, game);
                if (toReveal.size() > 1) {
                    permanentController.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)

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