Search in sources :

Example 51 with Cards

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

the class ScalpelexisEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (targetPlayer == null) {
        return false;
    }
    Set<String> cardNames = new HashSet<>();
    boolean doubleName;
    do {
        doubleName = false;
        Cards toExile = new CardsImpl(targetPlayer.getLibrary().getTopCards(game, 4));
        cardNames.clear();
        for (Card card : toExile.getCards(game)) {
            if (cardNames.contains(card.getName())) {
                doubleName = true;
                break;
            } else {
                cardNames.add(card.getName());
            }
        }
        targetPlayer.moveCards(toExile, Zone.EXILED, source, game);
    } while (doubleName);
    return true;
}
Also used : Player(mage.players.Player) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) HashSet(java.util.HashSet) Card(mage.cards.Card)

Example 52 with Cards

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

the class ShrineOfPiercingVisionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
    if (player == null || permanent == null) {
        return false;
    }
    Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, permanent.getCounters(game).getCount(CounterType.CHARGE)));
    if (!cards.isEmpty()) {
        player.lookAtCards(source, null, cards, game);
        TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card to put into your hand"));
        if (player.choose(Outcome.DrawCard, cards, target, game)) {
            Card card = cards.get(target.getFirstTarget(), game);
            if (card != null) {
                cards.remove(card);
                player.moveCards(card, Zone.HAND, source, game);
            }
        }
        player.putCardsOnBottomOfLibrary(cards, game, source, true);
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 53 with Cards

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

the class SoulflayerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent != null) {
        // one time abilities collect
        if (objectReference == null || !objectReference.refersTo(permanent, game)) {
            abilitiesToAdd = new HashSet<>();
            this.objectReference = new MageObjectReference(permanent, game);
            String keyString = CardUtil.getCardZoneString("delvedCards", source.getSourceId(), game, true);
            Cards delvedCards = (Cards) game.getState().getValue(keyString);
            if (delvedCards != null) {
                for (Card card : delvedCards.getCards(game)) {
                    if (!card.isCreature(game)) {
                        continue;
                    }
                    for (Ability cardAbility : card.getAbilities(game)) {
                        if (cardAbility instanceof FlyingAbility) {
                            abilitiesToAdd.add(FlyingAbility.getInstance());
                        }
                        if (cardAbility instanceof FirstStrikeAbility) {
                            abilitiesToAdd.add(FirstStrikeAbility.getInstance());
                        }
                        if (cardAbility instanceof DoubleStrikeAbility) {
                            abilitiesToAdd.add(DoubleStrikeAbility.getInstance());
                        }
                        if (cardAbility instanceof DeathtouchAbility) {
                            abilitiesToAdd.add(DeathtouchAbility.getInstance());
                        }
                        if (cardAbility instanceof HasteAbility) {
                            abilitiesToAdd.add(HasteAbility.getInstance());
                        }
                        if (cardAbility instanceof HexproofBaseAbility) {
                            abilitiesToAdd.add(HexproofAbility.getInstance());
                        }
                        if (cardAbility instanceof IndestructibleAbility) {
                            abilitiesToAdd.add(IndestructibleAbility.getInstance());
                        }
                        if (cardAbility instanceof LifelinkAbility) {
                            abilitiesToAdd.add(LifelinkAbility.getInstance());
                        }
                        if (cardAbility instanceof ReachAbility) {
                            abilitiesToAdd.add(ReachAbility.getInstance());
                        }
                        if (cardAbility instanceof TrampleAbility) {
                            abilitiesToAdd.add(TrampleAbility.getInstance());
                        }
                        if (cardAbility instanceof VigilanceAbility) {
                            abilitiesToAdd.add(VigilanceAbility.getInstance());
                        }
                    }
                }
            }
        }
        // all time abilities apply
        for (Ability ability : abilitiesToAdd) {
            permanent.addAbility(ability, source.getSourceId(), game);
        }
        return true;
    } else if (abilitiesToAdd != null) {
        abilitiesToAdd = null;
    }
    return false;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) Card(mage.cards.Card) MageObjectReference(mage.MageObjectReference) Cards(mage.cards.Cards)

Example 54 with Cards

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

the class SzatsWillEffect 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(game.getOpponents(source.getControllerId()).stream().map(game::getPlayer).filter(Objects::nonNull).map(Player::getGraveyard).flatMap(Collection::stream).collect(Collectors.toSet()));
    player.moveCards(cards, Zone.EXILED, source, game);
    cards.removeIf(uuid -> game.getState().getZone(uuid) != Zone.EXILED);
    int maxPower = cards.getCards(game).stream().filter(Objects::nonNull).filter(card -> card.isCreature(game)).map(MageObject::getPower).mapToInt(MageInt::getValue).max().orElse(0);
    if (maxPower > 0) {
        new BreedingPitThrullToken().putOntoBattlefield(maxPower, game, source, source.getControllerId());
    }
    return true;
}
Also used : Player(mage.players.Player) BreedingPitThrullToken(mage.game.permanent.token.BreedingPitThrullToken) Objects(java.util.Objects) Collection(java.util.Collection) MageInt(mage.MageInt) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 55 with Cards

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

the class ThoughtpickerWitchEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(this.getTargetPointer().getFirst(game, source));
    if (controller != null && opponent != null) {
        Cards cards = new CardsImpl(opponent.getLibrary().getTopCards(game, 2));
        if (!cards.isEmpty()) {
            TargetCard target = new TargetCardInLibrary(new FilterCard("card to exile"));
            if (controller.choose(Outcome.Exile, cards, target, game)) {
                Card card = cards.get(target.getFirstTarget(), game);
                if (card != null) {
                    cards.remove(card);
                    opponent.moveCards(card, Zone.EXILED, source, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

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