Search in sources :

Example 96 with Cards

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

the class CurseOfTheSwineEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Cards creaturesToExile = new CardsImpl();
    if (controller != null) {
        Map<UUID, Integer> playersWithTargets = new HashMap<>();
        for (UUID targetId : this.getTargetPointer().getTargets(game, source)) {
            Permanent creature = game.getPermanent(targetId);
            // TODO implement a way to verify that tokens are indeed exiled from the battlefield
            if (creature instanceof PermanentToken) {
                playersWithTargets.put(creature.getControllerId(), playersWithTargets.getOrDefault(creature.getControllerId(), 0) + 1);
            }
            if (creature != null) {
                creaturesToExile.add(creature);
            }
        }
        // move creatures to exile all at once
        controller.moveCards(creaturesToExile, Zone.EXILED, source, game);
        // Count all creatures actually exiled and add them to the player's count
        for (Card card : creaturesToExile.getCards(game)) {
            Permanent lkiP = game.getPermanentOrLKIBattlefield(card.getId());
            // note that tokens have no LKI once they are moved from the battlefield so they are handled earlier
            if (lkiP != null && game.getState().getZone(lkiP.getId()) == Zone.EXILED) {
                playersWithTargets.put(lkiP.getControllerId(), playersWithTargets.getOrDefault(lkiP.getControllerId(), 0) + 1);
            }
        }
        Boar2Token swineToken = new Boar2Token();
        for (Map.Entry<UUID, Integer> exiledByController : playersWithTargets.entrySet()) {
            swineToken.putOntoBattlefield(exiledByController.getValue(), game, source, exiledByController.getKey());
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) HashMap(java.util.HashMap) PermanentToken(mage.game.permanent.PermanentToken) Card(mage.cards.Card) UUID(java.util.UUID) Boar2Token(mage.game.permanent.token.Boar2Token) HashMap(java.util.HashMap) Map(java.util.Map) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 97 with Cards

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

the class GamePreserveEffect 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(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            cards.add(player.getLibrary().getFromTop(game));
        }
    }
    controller.revealCards(source, cards, game);
    if (cards.isEmpty() || cards.count(StaticFilters.FILTER_CARD_NON_CREATURE, game) > 0) {
        return false;
    }
    controller.moveCards(cards.getCards(game), Zone.BATTLEFIELD, source, game, false, false, true, null);
    return true;
}
Also used : Player(mage.players.Player) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 98 with Cards

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

the class HarnessInfinityEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Cards hand = new CardsImpl(player.getHand());
    Cards graveyard = new CardsImpl(player.getGraveyard());
    player.moveCards(hand, Zone.GRAVEYARD, source, game);
    player.moveCards(graveyard, Zone.HAND, source, game);
    return true;
}
Also used : Player(mage.players.Player) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 99 with Cards

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

the class HarmonicConvergenceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            FilterEnchantmentPermanent filter = new FilterEnchantmentPermanent();
            filter.add(new OwnerIdPredicate(player.getId()));
            Cards toLib = new CardsImpl();
            for (Permanent enchantment : game.getBattlefield().getActivePermanents(filter, playerId, source.getSourceId(), game)) {
                toLib.add(enchantment);
            }
            player.putCardsOnTopOfLibrary(toLib, game, source, true);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) FilterEnchantmentPermanent(mage.filter.common.FilterEnchantmentPermanent) Permanent(mage.game.permanent.Permanent) FilterEnchantmentPermanent(mage.filter.common.FilterEnchantmentPermanent) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 100 with Cards

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

the class KindredSummonsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        SubType subType = ChooseCreatureTypeEffect.getChosenCreatureType(source.getSourceId(), game);
        if (subType == null) {
            return false;
        }
        FilterControlledCreaturePermanent filterPermanent = new FilterControlledCreaturePermanent("creature you control of the chosen type");
        filterPermanent.add(subType.getPredicate());
        int numberOfCards = game.getBattlefield().countAll(filterPermanent, source.getControllerId(), game);
        Cards revealed = new CardsImpl();
        Set<Card> chosenSubtypeCreatureCards = new LinkedHashSet<>();
        Cards otherCards = new CardsImpl();
        FilterCreatureCard filterCard = new FilterCreatureCard("creature card of the chosen type");
        filterCard.add(subType.getPredicate());
        if (numberOfCards == 0) {
            // no matches so nothing is revealed
            game.informPlayers("There are 0 creature cards of the chosen type in " + controller.getName() + "'s library.");
            return true;
        }
        for (Card card : controller.getLibrary().getCards(game)) {
            revealed.add(card);
            if (card != null && filterCard.match(card, game)) {
                chosenSubtypeCreatureCards.add(card);
                if (chosenSubtypeCreatureCards.size() == numberOfCards) {
                    break;
                }
            } else {
                otherCards.add(card);
            }
        }
        controller.revealCards(source, revealed, game);
        controller.moveCards(chosenSubtypeCreatureCards, Zone.BATTLEFIELD, source, game);
        if (!otherCards.isEmpty()) {
            controller.putCardsOnTopOfLibrary(otherCards, game, source, false);
            controller.shuffleLibrary(source, game);
        }
        return true;
    }
    return false;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) SubType(mage.constants.SubType) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterCreatureCard(mage.filter.common.FilterCreatureCard) 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