Search in sources :

Example 86 with CardsImpl

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

the class TreasureHuntEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null && controller.getLibrary().hasCards()) {
        CardsImpl cards = new CardsImpl();
        for (Card card : controller.getLibrary().getCards(game)) {
            cards.add(card);
            if (!card.isLand(game)) {
                break;
            }
        }
        controller.revealCards(source, cards, game);
        controller.moveCards(cards, Zone.HAND, source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 87 with CardsImpl

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

the class VesselOfNascencyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller != null && sourceObject != null) {
        Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 4));
        boolean properCardFound = cards.count(filterPutInHand, source.getControllerId(), source.getSourceId(), game) > 0;
        if (!cards.isEmpty()) {
            controller.revealCards(sourceObject.getName(), cards, game);
            TargetCard target = new TargetCard(Zone.LIBRARY, filterPutInHand);
            if (properCardFound && controller.chooseUse(outcome, "Put an artifact, creature, enchantment, land, or planeswalker card into your hand?", source, game) && controller.choose(Outcome.DrawCard, cards, target, game)) {
                Card card = game.getCard(target.getFirstTarget());
                if (card != null) {
                    cards.remove(card);
                    controller.moveCards(card, Zone.HAND, source, game);
                }
            }
            controller.moveCards(cards, Zone.GRAVEYARD, source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 88 with CardsImpl

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

the class VictimizeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        SacrificeTargetCost cost = new SacrificeTargetCost(new TargetControlledCreaturePermanent(FILTER_CONTROLLED_CREATURE_SHORT_TEXT));
        if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
            // To end effects of the sacrificed creature
            game.getState().processAction(game);
            controller.moveCards(new CardsImpl(getTargetPointer().getTargets(game, source)).getCards(game), Zone.BATTLEFIELD, source, game, true, false, false, null);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) CardsImpl(mage.cards.CardsImpl)

Example 89 with CardsImpl

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

the class WizardMentorEffect 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.getSourcePermanentIfItStillExists(game));
    cards.add(source.getFirstTarget());
    return player.moveCards(cards, Zone.HAND, source, game);
}
Also used : Player(mage.players.Player) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 90 with CardsImpl

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

the class AmplifyEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Permanent sourceCreature = ((EntersTheBattlefieldEvent) event).getTarget();
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null || sourceCreature == null) {
        return false;
    }
    FilterCreatureCard filter = new FilterCreatureCard("creatures cards to reveal");
    filter.add(new AmplifyPredicate(sourceCreature));
    // You can’t reveal this card or any other cards that are entering the battlefield at the same time as this card.
    filter.add(Predicates.not(new CardIdPredicate(source.getSourceId())));
    for (Permanent enteringPermanent : game.getPermanentsEntering().values()) {
        filter.add(Predicates.not(new CardIdPredicate(enteringPermanent.getId())));
    }
    if (controller.getHand().count(filter, source.getSourceId(), source.getControllerId(), game) <= 0) {
        return false;
    }
    if (!controller.chooseUse(outcome, "Reveal cards to Amplify?", source, game)) {
        return false;
    }
    TargetCardInHand target = new TargetCardInHand(0, Integer.MAX_VALUE, filter);
    if (controller.chooseTarget(outcome, target, source, game) && !target.getTargets().isEmpty()) {
        Cards cards = new CardsImpl();
        cards.addAll(target.getTargets());
        int amountCounters = cards.size() * amplifyFactor.getFactor();
        sourceCreature.addCounters(CounterType.P1P1.createInstance(amountCounters), source.getControllerId(), source, game);
        controller.revealCards(sourceCreature.getIdName(), cards, game);
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Permanent(mage.game.permanent.Permanent) EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent) TargetCardInHand(mage.target.common.TargetCardInHand) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

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