Search in sources :

Example 56 with Card

use of mage.cards.Card in project mage by magefree.

the class NobleBenefactorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                TargetCardInLibrary target = new TargetCardInLibrary();
                if (player.chooseUse(Outcome.Benefit, "Search your library for a card to put into your hand?", source, game)) {
                    player.searchLibrary(target, source, game);
                    for (UUID cardId : target.getTargets()) {
                        Card card = player.getLibrary().getCard(cardId, game);
                        if (card != null) {
                            player.moveCards(card, Zone.HAND, source, game);
                        }
                    }
                    player.shuffleLibrary(source, game);
                }
            }
        }
        // prevent undo
        controller.resetStoredBookmark(game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card)

Example 57 with Card

use of mage.cards.Card in project mage by magefree.

the class NomadMythmakerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Card aura = game.getCard(source.getFirstTarget());
    if (controller == null || aura == null) {
        return false;
    }
    FilterControlledCreaturePermanent FILTER = new FilterControlledCreaturePermanent("Choose a creature you control");
    TargetControlledPermanent target = new TargetControlledPermanent(FILTER);
    target.setNotTarget(true);
    if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent != null && !permanent.cantBeAttachedBy(aura, source, game, false)) {
            game.getState().setValue("attachTo:" + aura.getId(), permanent);
            controller.moveCards(aura, Zone.BATTLEFIELD, source, game);
            return permanent.addAttachment(aura.getId(), source, game);
        }
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 58 with Card

use of mage.cards.Card in project mage by magefree.

the class NissaStewardOfElementsToken method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int count = 1 + new CountersSourceCount(CounterType.LOYALTY).calculate(game, source, this);
    FilterPermanentCard filter = new FilterPermanentCard();
    filter.add(Predicates.or(CardType.CREATURE.getPredicate(), CardType.LAND.getPredicate()));
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, count));
    Card card = controller.getLibrary().getFromTop(game);
    if (card != null) {
        controller.lookAtCards(source, null, new CardsImpl(card), game);
        if (filter.match(card, game)) {
            if (controller.chooseUse(outcome, "Put " + card.getName() + " onto the battlefield?", source, game)) {
                controller.moveCards(card, Zone.BATTLEFIELD, source, game);
            }
        }
    }
    return true;
}
Also used : CountersSourceCount(mage.abilities.dynamicvalue.common.CountersSourceCount) Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card) FilterPermanentCard(mage.filter.common.FilterPermanentCard)

Example 59 with Card

use of mage.cards.Card in project mage by magefree.

the class PsychicIntrusionSpendAnyManaEffect 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 (opponent != null && sourceObject != null) {
        opponent.revealCards(sourceObject.getName(), opponent.getHand(), game);
        Player controller = game.getPlayer(source.getControllerId());
        if (controller != null) {
            int cardsGraveyard = opponent.getGraveyard().count(filter, game);
            int cardsHand = opponent.getHand().count(filter, game);
            boolean fromHand = false;
            if (cardsGraveyard > 0 && cardsHand > 0) {
                if (controller.chooseUse(Outcome.Detriment, "Exile card from opponents Hand?", source, game)) {
                    fromHand = true;
                }
            } else {
                if (cardsHand > 0) {
                    fromHand = true;
                }
            }
            Card card = null;
            if (cardsHand > 0 && fromHand) {
                TargetCard target = new TargetCard(Zone.HAND, filter);
                if (controller.choose(Outcome.Benefit, opponent.getHand(), target, game)) {
                    card = opponent.getHand().get(target.getFirstTarget(), game);
                }
            }
            if (cardsGraveyard > 0 && !fromHand) {
                TargetCard target = new TargetCard(Zone.GRAVEYARD, filter);
                if (controller.choose(Outcome.Benefit, opponent.getGraveyard(), target, game)) {
                    card = opponent.getGraveyard().get(target.getFirstTarget(), game);
                }
            }
            if (card != null) {
                // move card to exile
                UUID exileId = CardUtil.getCardExileZoneId(game, source);
                controller.moveCardToExileWithInfo(card, exileId, sourceObject.getIdName(), source, game, fromHand ? Zone.HAND : Zone.GRAVEYARD, true);
                // allow to cast the card
                ContinuousEffect effect = new PsychicIntrusionCastFromExileEffect();
                effect.setTargetPointer(new FixedTarget(card.getId()));
                game.addEffect(effect, source);
                // and you may spend mana as though it were mana of any color to cast it
                effect = new PsychicIntrusionSpendAnyManaEffect();
                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) TargetCard(mage.target.TargetCard) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 60 with Card

use of mage.cards.Card in project mage by magefree.

the class PsychicTheftWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
    if (opponent == null) {
        return false;
    }
    opponent.revealCards(CardUtil.getSourceName(game, source), opponent.getHand(), game);
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int cardsHand = opponent.getHand().count(filter, game);
    Card chosenCard = null;
    if (cardsHand > 0) {
        TargetCard target = new TargetCard(Zone.HAND, filter);
        if (controller.choose(Outcome.Exile, opponent.getHand(), target, game)) {
            chosenCard = opponent.getHand().get(target.getFirstTarget(), game);
        }
    }
    if (chosenCard == null) {
        return false;
    }
    controller.moveCardToExileWithInfo(chosenCard, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source), source, game, Zone.HAND, true);
    CardUtil.makeCardPlayable(game, source, chosenCard, Duration.Custom, false);
    game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new ConditionalOneShotEffect(new ReturnFromExileEffect(Zone.HAND), new PsychicTheftCondition(chosenCard, game), "if you haven't cast it, return it to its owner's hand.")), source);
    return true;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) ReturnFromExileEffect(mage.abilities.effects.common.ReturnFromExileEffect) TargetCard(mage.target.TargetCard) ConditionalOneShotEffect(mage.abilities.decorator.ConditionalOneShotEffect) TargetCard(mage.target.TargetCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Card(mage.cards.Card)

Aggregations

Card (mage.cards.Card)1448 Player (mage.players.Player)1096 Permanent (mage.game.permanent.Permanent)423 FilterCard (mage.filter.FilterCard)381 UUID (java.util.UUID)340 CardsImpl (mage.cards.CardsImpl)253 MageObject (mage.MageObject)212 FixedTarget (mage.target.targetpointer.FixedTarget)173 TargetCard (mage.target.TargetCard)165 Cards (mage.cards.Cards)159 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)111 ContinuousEffect (mage.abilities.effects.ContinuousEffect)99 TargetCardInHand (mage.target.common.TargetCardInHand)98 Target (mage.target.Target)86 HashSet (java.util.HashSet)85 FilterCreatureCard (mage.filter.common.FilterCreatureCard)84 ApprovingObject (mage.ApprovingObject)77 Ability (mage.abilities.Ability)71 TargetPlayer (mage.target.TargetPlayer)67 TargetPermanent (mage.target.TargetPermanent)64