Search in sources :

Example 66 with Cards

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

the class DesperateResearchEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
    Player player = game.getPlayer(source.getControllerId());
    if (player == null || cardName == null) {
        return false;
    }
    Cards cardsToExile = new CardsImpl(player.getLibrary().getTopCards(game, 7));
    player.revealCards(source, cardsToExile, game);
    FilterCard filter = new FilterCard();
    filter.add(new NamePredicate(cardName));
    Cards cardsToKeep = new CardsImpl(cardsToExile.getCards(filter, game));
    cardsToExile.removeAll(cardsToKeep);
    player.moveCards(cardsToKeep, Zone.HAND, source, game);
    player.moveCards(cardsToExile, Zone.EXILED, source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 67 with Cards

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

the class DreamPillagerEffect 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) {
        int amount = (Integer) getValue("damage");
        if (amount > 0) {
            Set<Card> cards = controller.getLibrary().getTopCards(game, amount);
            if (!cards.isEmpty()) {
                controller.moveCards(cards, Zone.EXILED, source, game);
                Cards canBeCast = new CardsImpl();
                for (Card card : cards) {
                    if (!card.isLand(game)) {
                        canBeCast.add(card);
                    }
                }
                ContinuousEffect effect = new PlayFromNotOwnHandZoneTargetEffect(Zone.EXILED, Duration.EndOfTurn);
                effect.setTargetPointer(new FixedTargets(canBeCast, game));
                game.addEffect(effect, source);
            }
            return true;
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) PlayFromNotOwnHandZoneTargetEffect(mage.abilities.effects.common.asthought.PlayFromNotOwnHandZoneTargetEffect) FixedTargets(mage.target.targetpointer.FixedTargets) MageObject(mage.MageObject) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 68 with Cards

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

the class HonorTheFallenEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Cards cards = new CardsImpl();
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        cards.addAll(player.getGraveyard().getCards(StaticFilters.FILTER_CARD_CREATURE, game));
    }
    controller.moveCards(cards, Zone.EXILED, source, game);
    int count = cards.stream().map(game.getState()::getZone).map(Zone.EXILED::equals).mapToInt(x -> x ? 1 : 0).sum();
    controller.gainLife(count, game, source);
    return true;
}
Also used : StaticFilters(mage.filter.StaticFilters) Zone(mage.constants.Zone) Cards(mage.cards.Cards) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) Ability(mage.abilities.Ability) Player(mage.players.Player) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 69 with Cards

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

the class JaceTheMindSculptorEffect2 method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player player = game.getPlayer(source.getFirstTarget());
    if (controller != null && player != null) {
        Card card = player.getLibrary().getFromTop(game);
        if (card != null) {
            Cards cards = new CardsImpl(card);
            controller.lookAtCards("Jace, the Mind Sculptor", cards, game);
            if (controller.chooseUse(outcome, "Put that card on the bottom of its owner's library?", source, game)) {
                controller.moveCardToLibraryWithInfo(card, source, game, Zone.LIBRARY, false, false);
            } else {
                game.informPlayers(controller.getLogName() + " puts the card back on top of the library.");
            }
            return true;
        }
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 70 with Cards

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

the class LichsMirrorEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Player player = game.getPlayer(event.getPlayerId());
    if (player != null) {
        Cards toLib = new CardsImpl();
        FilterControlledPermanent filter = new FilterControlledPermanent();
        filter.add(new OwnerIdPredicate(player.getId()));
        toLib.addAll(player.getHand());
        toLib.addAll(player.getGraveyard());
        for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
            toLib.add(permanent);
        }
        player.shuffleCardsToLibrary(toLib, game, source);
        game.getState().processAction(game);
        // original event is not a draw event, so skip it in params
        player.drawCards(7, source, game);
        player.setLife(20, game, source);
    }
    // replace the loses event
    return true;
}
Also used : Player(mage.players.Player) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Aggregations

Cards (mage.cards.Cards)354 Player (mage.players.Player)342 CardsImpl (mage.cards.CardsImpl)328 Card (mage.cards.Card)157 UUID (java.util.UUID)104 FilterCard (mage.filter.FilterCard)86 TargetCard (mage.target.TargetCard)84 MageObject (mage.MageObject)73 Permanent (mage.game.permanent.Permanent)71 TargetPlayer (mage.target.TargetPlayer)35 OneShotEffect (mage.abilities.effects.OneShotEffect)27 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)27 Ability (mage.abilities.Ability)25 Target (mage.target.Target)24 TargetCardInHand (mage.target.common.TargetCardInHand)24 Game (mage.game.Game)23 CardSetInfo (mage.cards.CardSetInfo)22 CardImpl (mage.cards.CardImpl)21 CardType (mage.constants.CardType)21 FilterPermanent (mage.filter.FilterPermanent)19