Search in sources :

Example 31 with Cards

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

the class BalancingActEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int minPermanent = Integer.MAX_VALUE, minCard = Integer.MAX_VALUE;
        // count minimal permanents
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                int count = game.getBattlefield().getActivePermanents(new FilterControlledPermanent(), player.getId(), source.getSourceId(), game).size();
                if (count < minPermanent) {
                    minPermanent = count;
                }
            }
        }
        // sacrifice permanents over the minimum
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                TargetControlledPermanent target = new TargetControlledPermanent(minPermanent, minPermanent, new FilterControlledPermanent(), true);
                if (target.choose(Outcome.Benefit, player.getId(), source.getSourceId(), game)) {
                    for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterControlledPermanent(), player.getId(), source.getSourceId(), game)) {
                        if (permanent != null && !target.getTargets().contains(permanent.getId())) {
                            permanent.sacrifice(source, game);
                        }
                    }
                }
            }
        }
        // count minimal cards in hand
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                int count = player.getHand().size();
                if (count < minCard) {
                    minCard = count;
                }
            }
        }
        // discard cards over the minimum
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                TargetCardInHand target = new TargetCardInHand(minCard, new FilterCard());
                if (target.choose(Outcome.Benefit, player.getId(), source.getSourceId(), game)) {
                    Cards cards = player.getHand().copy();
                    cards.removeIf(target.getTargets()::contains);
                    player.discard(cards, false, source, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Cards(mage.cards.Cards)

Example 32 with Cards

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

the class CelebrateTheHarvestEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int powerCount = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CONTROLLED_CREATURE, source.getControllerId(), source.getSourceId(), game).stream().filter(Objects::nonNull).map(MageObject::getPower).mapToInt(MageInt::getValue).distinct().map(x -> 1).sum();
    TargetCardInLibrary target = new TargetCardInLibrary(0, powerCount, StaticFilters.FILTER_CARD_BASIC_LAND);
    player.searchLibrary(target, source, game);
    Cards cards = new CardsImpl();
    target.getTargets().stream().map(cardId -> player.getLibrary().getCard(cardId, game)).forEach(cards::add);
    player.moveCards(cards.getCards(game), Zone.BATTLEFIELD, source, game, true, false, true, null);
    player.shuffleLibrary(source, game);
    return true;
}
Also used : StaticFilters(mage.filter.StaticFilters) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Zone(mage.constants.Zone) Cards(mage.cards.Cards) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) CardsImpl(mage.cards.CardsImpl) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) MageObject(mage.MageObject) CovenHint(mage.abilities.hint.common.CovenHint) Ability(mage.abilities.Ability) Player(mage.players.Player) MageObject(mage.MageObject) CovenHint(mage.abilities.hint.common.CovenHint) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 33 with Cards

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

the class ColfenorsPlansLookAtCardEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Cards toExile = new CardsImpl(controller.getLibrary().getTopCards(game, 7));
        UUID exileId = CardUtil.getCardExileZoneId(game, source);
        controller.moveCardsToExile(toExile.getCards(game), source, game, false, exileId, CardUtil.createObjectRealtedWindowTitle(source, game, null));
        ExileZone exileZone = game.getExile().getExileZone(exileId);
        if (exileZone != null) {
            for (Card card : exileZone.getCards(game)) {
                if (card != null) {
                    card.setFaceDown(true, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ExileZone(mage.game.ExileZone) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 34 with Cards

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

the class DanceOfTheManseEffect 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().stream().map(Target::getTargets).flatMap(Collection::stream).map(game::getCard).filter(Objects::nonNull).collect(Collectors.toSet()));
    player.moveCards(cards, Zone.BATTLEFIELD, source, game);
    if (source.getManaCostsToPay().getX() < 6) {
        return true;
    }
    cards.stream().map(game::getPermanent).filter(Objects::nonNull).forEach(permanent -> {
        ContinuousEffect effect = new AddCardTypeTargetEffect(Duration.EndOfGame, CardType.CREATURE);
        effect.setTargetPointer(new FixedTarget(permanent, game));
        game.addEffect(effect, source);
        effect = new SetPowerToughnessTargetEffect(4, 4, Duration.EndOfGame);
        effect.setTargetPointer(new FixedTarget(permanent, game));
        game.addEffect(effect, source);
    });
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Objects(java.util.Objects) Collection(java.util.Collection) ContinuousEffect(mage.abilities.effects.ContinuousEffect) SetPowerToughnessTargetEffect(mage.abilities.effects.common.continuous.SetPowerToughnessTargetEffect) AddCardTypeTargetEffect(mage.abilities.effects.common.continuous.AddCardTypeTargetEffect) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 35 with Cards

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

the class DanceOfManyExileTokenEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        List<Permanent> tokenPermanents = (List<Permanent>) game.getState().getValue(source.getSourceId() + "_token");
        if (tokenPermanents != null) {
            Cards cards = new CardsImpl();
            for (Permanent permanent : tokenPermanents) {
                cards.add(permanent);
            }
            controller.moveCards(cards, Zone.EXILED, source, game);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) List(java.util.List) 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