Search in sources :

Example 96 with CardsImpl

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

the class DescendantsPathEffect 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()) {
            Card card = controller.getLibrary().getFromTop(game);
            if (card == null) {
                return false;
            }
            controller.revealCards(sourceObject.getIdName(), new CardsImpl(card), game);
            if (card.isCreature(game)) {
                FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
                boolean found = false;
                for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, controller.getId(), game)) {
                    if (card.shareCreatureTypes(game, permanent)) {
                        found = true;
                        break;
                    }
                }
                if (found) {
                    game.informPlayers(sourceObject.getLogName() + ": Found a creature that shares a creature type with the revealed card.");
                    if (controller.chooseUse(Outcome.Benefit, "Cast the card?", source, game)) {
                        game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                        controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                        game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
                    } else {
                        game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " canceled casting the card.");
                        controller.getLibrary().putOnBottom(card, game);
                    }
                } else {
                    game.informPlayers(sourceObject.getLogName() + ": No creature that shares a creature type with the revealed card.");
                    controller.getLibrary().putOnBottom(card, game);
                }
            } else {
                game.informPlayers(sourceObject.getLogName() + ": Put " + card.getLogName() + " on the bottom.");
                controller.getLibrary().putOnBottom(card, game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) MageObject(mage.MageObject) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 97 with CardsImpl

use of mage.cards.CardsImpl 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 98 with CardsImpl

use of mage.cards.CardsImpl 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 99 with CardsImpl

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

the class EtherWellEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (player == null || permanent == null) {
        return false;
    }
    if (permanent.getColor(game).isRed() && player.chooseUse(outcome, "Put " + permanent.getLogName() + " on the bottom of its owner's library?", source, game)) {
        player.putCardsOnBottomOfLibrary(permanent, game, source, true);
        return true;
    }
    player.putCardsOnTopOfLibrary(new CardsImpl(permanent), game, source, true);
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) CardsImpl(mage.cards.CardsImpl)

Example 100 with CardsImpl

use of mage.cards.CardsImpl 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)

Aggregations

CardsImpl (mage.cards.CardsImpl)507 Player (mage.players.Player)497 Cards (mage.cards.Cards)328 Card (mage.cards.Card)253 UUID (java.util.UUID)135 Permanent (mage.game.permanent.Permanent)114 FilterCard (mage.filter.FilterCard)108 MageObject (mage.MageObject)106 TargetCard (mage.target.TargetCard)99 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)53 TargetPlayer (mage.target.TargetPlayer)47 TargetCardInHand (mage.target.common.TargetCardInHand)41 OneShotEffect (mage.abilities.effects.OneShotEffect)37 Target (mage.target.Target)32 Ability (mage.abilities.Ability)27 FilterPermanent (mage.filter.FilterPermanent)27 CardSetInfo (mage.cards.CardSetInfo)25 Game (mage.game.Game)25 CardImpl (mage.cards.CardImpl)24 FilterCreatureCard (mage.filter.common.FilterCreatureCard)23