Search in sources :

Example 46 with FilterCreatureCard

use of mage.filter.common.FilterCreatureCard in project mage by magefree.

the class GatherThePackEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller == null || sourceObject == null) {
        return false;
    }
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 5));
    if (!cards.isEmpty()) {
        controller.revealCards(sourceObject.getIdName(), cards, game);
        int creatures = cards.count(StaticFilters.FILTER_CARD_CREATURE, source.getSourceId(), source.getControllerId(), game);
        if (creatures > 0) {
            int max = 1;
            if (SpellMasteryCondition.instance.apply(game, source) && creatures > 1) {
                max++;
            }
            TargetCard target = new TargetCard(0, max, Zone.LIBRARY, new FilterCreatureCard("creature card" + (max > 1 ? "s" : "") + " to put into your hand"));
            if (controller.choose(Outcome.PutCreatureInPlay, cards, target, game)) {
                Cards cardsToHand = new CardsImpl(target.getTargets());
                if (!cardsToHand.isEmpty()) {
                    cards.removeAll(cardsToHand);
                    controller.moveCards(cardsToHand, Zone.HAND, source, game);
                }
            }
        }
        if (!cards.isEmpty()) {
            controller.moveCards(cards, Zone.GRAVEYARD, source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 47 with FilterCreatureCard

use of mage.filter.common.FilterCreatureCard in project mage by magefree.

the class GuildFeudEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
    Player controller = game.getPlayer(source.getControllerId());
    Permanent opponentCreature = null;
    Permanent controllerCreature = null;
    MageObject sourceObject = source.getSourceObject(game);
    if (opponent != null && controller != null && sourceObject != null) {
        for (int activePlayer = 0; activePlayer < 2; activePlayer++) {
            Player player = (activePlayer == 0 ? opponent : controller);
            Cards topThreeCards = new CardsImpl(player.getLibrary().getTopCards(game, 3));
            player.revealCards(source, player.getName() + " top library cards", topThreeCards, game);
            Card creatureToBattlefield;
            if (!topThreeCards.isEmpty()) {
                if (player.chooseUse(Outcome.PutCreatureInPlay, "Put a creature card among them to the battlefield?", source, game)) {
                    TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCreatureCard("creature card to put on the battlefield"));
                    if (player.choose(Outcome.PutCreatureInPlay, topThreeCards, target, game)) {
                        creatureToBattlefield = topThreeCards.get(target.getFirstTarget(), game);
                        if (creatureToBattlefield != null) {
                            topThreeCards.remove(creatureToBattlefield);
                            if (player.moveCards(creatureToBattlefield, Zone.BATTLEFIELD, source, game)) {
                                if (activePlayer == 0) {
                                    opponentCreature = game.getPermanent(creatureToBattlefield.getId());
                                } else {
                                    controllerCreature = game.getPermanent(creatureToBattlefield.getId());
                                }
                            }
                        }
                    }
                }
                player.moveCards(topThreeCards, Zone.GRAVEYARD, source, game);
            }
        }
        // If two creatures are put onto the battlefield this way, those creatures fight each other
        if (opponentCreature != null && controllerCreature != null) {
            opponentCreature.fight(controllerCreature, source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetCard(mage.target.TargetCard)

Example 48 with FilterCreatureCard

use of mage.filter.common.FilterCreatureCard in project mage by magefree.

the class MausoleumTurnkeyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        UUID opponentId = null;
        if (game.getOpponents(controller.getId()).size() > 1) {
            Target target = new TargetOpponent(true);
            if (controller.chooseTarget(outcome, target, source, game)) {
                opponentId = target.getFirstTarget();
            }
        } else {
            opponentId = game.getOpponents(controller.getId()).iterator().next();
        }
        if (opponentId != null) {
            Player opponent = game.getPlayer(opponentId);
            if (opponent != null) {
                FilterCreatureCard filter = new FilterCreatureCard("creature card from " + controller.getLogName() + " graveyard");
                filter.add(new OwnerIdPredicate(controller.getId()));
                Target target = new TargetCardInGraveyard(filter);
                opponent.chooseTarget(outcome, target, source, game);
                Card card = game.getCard(target.getFirstTarget());
                if (card != null) {
                    controller.moveCards(card, Zone.HAND, source, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) FilterCreatureCard(mage.filter.common.FilterCreatureCard) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) UUID(java.util.UUID) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card)

Example 49 with FilterCreatureCard

use of mage.filter.common.FilterCreatureCard in project mage by magefree.

the class ToothAndNailPutCreatureOnBattlefieldEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    TargetCardInHand target = new TargetCardInHand(0, 2, new FilterCreatureCard("creature cards"));
    if (controller.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game)) {
        return controller.moveCards(new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD, source, game, false, false, false, null);
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetCardInHand(mage.target.common.TargetCardInHand) CardsImpl(mage.cards.CardsImpl)

Example 50 with FilterCreatureCard

use of mage.filter.common.FilterCreatureCard in project mage by magefree.

the class GrimCaptainsCallEffect method returnToHand.

private void returnToHand(Game game, SubType subType, Player controller, Ability source) {
    FilterCreatureCard filter = new FilterCreatureCard(subType.getDescription() + " card");
    filter.add(subType.getPredicate());
    TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(new FilterCreatureCard(filter));
    if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
        if (controller.chooseTarget(outcome, target, source, game)) {
            Card card = game.getCard(target.getFirstTarget());
            if (card != null) {
                controller.moveCards(card, Zone.HAND, source, game);
            }
        }
    }
}
Also used : FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card)

Aggregations

FilterCreatureCard (mage.filter.common.FilterCreatureCard)69 Player (mage.players.Player)58 Card (mage.cards.Card)31 FilterCard (mage.filter.FilterCard)26 Permanent (mage.game.permanent.Permanent)22 UUID (java.util.UUID)17 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)17 TargetCard (mage.target.TargetCard)16 CardsImpl (mage.cards.CardsImpl)15 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)15 TargetCardInGraveyard (mage.target.common.TargetCardInGraveyard)14 MageObject (mage.MageObject)13 OwnerIdPredicate (mage.filter.predicate.card.OwnerIdPredicate)10 Target (mage.target.Target)10 HashSet (java.util.HashSet)8 Cards (mage.cards.Cards)8 TargetCardInYourGraveyard (mage.target.common.TargetCardInYourGraveyard)7 Ability (mage.abilities.Ability)6 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)6 OneShotEffect (mage.abilities.effects.OneShotEffect)4