Search in sources :

Example 6 with CardsImpl

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

the class DeliverUntoEvilEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Cards cards = new CardsImpl(source.getTargets().get(0).getTargets());
    if (cards.isEmpty()) {
        return false;
    }
    if (!game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game).isEmpty()) {
        return player.moveCards(cards, Zone.HAND, source, game);
    }
    TargetOpponent targetOpponent = new TargetOpponent();
    targetOpponent.setNotTarget(true);
    if (!player.choose(outcome, targetOpponent, source.getSourceId(), game)) {
        return false;
    }
    Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
    if (opponent == null) {
        return false;
    }
    TargetCard targetCard = new TargetCardInGraveyard(Math.min(2, cards.size()), filter2);
    if (!opponent.choose(outcome, cards, targetCard, game)) {
        return false;
    }
    cards.removeAll(targetCard.getTargets());
    return player.moveCards(cards, Zone.HAND, source, game);
}
Also used : Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 7 with CardsImpl

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

the class DimensionalBreachReturnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(game.getActivePlayerId());
    if (player == null) {
        return false;
    }
    Cards cards = new CardsImpl(morSet.stream().map(mor -> mor.getCard(game)).filter(Objects::nonNull).filter(c -> c.isOwnedBy(game.getActivePlayerId())).collect(Collectors.toSet()));
    if (cards.isEmpty()) {
        return false;
    }
    if (cards.size() > 1) {
        TargetCard target = new TargetCardInExile(StaticFilters.FILTER_CARD);
        target.setNotTarget(true);
        player.choose(outcome, cards, target, game);
        cards.clear();
        cards.add(target.getFirstTarget());
    }
    return player.moveCards(cards, Zone.BATTLEFIELD, source, game);
}
Also used : Player(mage.players.Player) TargetCardInExile(mage.target.common.TargetCardInExile) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 8 with CardsImpl

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

the class DiscordantDirgeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent discordantDirge = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (discordantDirge == null) {
        return false;
    }
    int verseCounters = discordantDirge.getCounters(game).getCount(CounterType.VERSE);
    Player targetOpponent = game.getPlayer(source.getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    if (targetOpponent == null || controller == null) {
        return false;
    }
    controller.lookAtCards(targetOpponent.getName() + " hand", targetOpponent.getHand(), game);
    TargetCard target = new TargetCard(0, verseCounters, Zone.HAND, new FilterCard());
    target.setNotTarget(true);
    if (!controller.choose(Outcome.Benefit, targetOpponent.getHand(), target, game)) {
        return false;
    }
    targetOpponent.discard(new CardsImpl(target.getTargets()), false, source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCard(mage.target.TargetCard) CardsImpl(mage.cards.CardsImpl)

Example 9 with CardsImpl

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

the class ElvishSoultillerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getObject(source.getSourceId());
    if (controller != null && mageObject != null) {
        Choice typeChoice = new ChoiceCreatureType(mageObject);
        if (controller.choose(outcome, typeChoice, game)) {
            if (!game.isSimulation()) {
                game.informPlayers(mageObject.getName() + ": " + controller.getLogName() + " has chosen " + typeChoice.getChoice());
            }
            Cards cardsToLibrary = new CardsImpl();
            FilterCreatureCard filter = new FilterCreatureCard();
            filter.add(SubType.byDescription(typeChoice.getChoice()).getPredicate());
            cardsToLibrary.addAll(controller.getGraveyard().getCards(filter, source.getSourceId(), source.getControllerId(), game));
            controller.putCardsOnTopOfLibrary(cardsToLibrary, game, source, false);
            controller.shuffleLibrary(source, game);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Choice(mage.choices.Choice) MageObject(mage.MageObject) ChoiceCreatureType(mage.choices.ChoiceCreatureType) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 10 with CardsImpl

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

the class FieldOfRuinEffect 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(0, 1, StaticFilters.FILTER_CARD_BASIC_LAND);
                if (player.searchLibrary(target, source, game)) {
                    player.moveCards(new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD, source, game);
                    player.shuffleLibrary(source, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) 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